var locationType = {
		"7":"地铁站",
		"8":"商业地点",
		"9":"小区",
		"10":"公交车站"
}
var rentTimeType = {
		"4":"短租",
		"5":"长租"
}
var HomeDetail=({
	queryHomeDetailByHouseId:function(houseId){
		var search = $("#search").val();
		$.ajax({
			type : "POST",
			dataType : 'json',
			url :  "../house/queryHomeDetailByHouseId.do",
			data : {
				"phone" : HomeDetail.getCookie("phone"),
				"houseId":houseId
			},
			success : function(data) {
				console.log(data);
				var html ="";
				if(data.result){
					//轮播图片
					if(data.houseImg !=null && data.houseImg.length>0){
						var imgHtml = "";
						imgHtml+="<ul id=\"imagesUl\">";
						$(data.houseImg).each(function(i,n){
							imgHtml+="<li data-background='"+n.imgUrl+"' style='height: 300px'></li>";
						})
						imgHtml+="</ul>";
						$(".flicker-example").html(imgHtml);
						$('.flicker-example').flickerplate({
				            auto_flick 				: true,
				            auto_flick_delay 		: 8,
				            flick_animation 		: 'transform-slide'
				        });
					}

					//详情
					if(data.houseDetail!=null){
						var res = data.houseDetail;
						title = res.houseName;
						sharLink ="http://lanjushiye.com.cn/LanJuPublic/jsp/houseDetails.html?houseId="+res.houseId;
						$("#title").text(res.houseName);
						$(".title").text(res.houseName);
						$("#price").text("￥"+res.price+"/月");
						$("#jl").text(res.area+data.community.community_name);
						$("#size").text(""+res.houseSize+"㎡（建筑面积）");
						$("#houseLayout").text(res.houseLayout);
						$("#elevator").text(res.elevator == 1?"有":"无");
						$("#towards").text(res.towards);
						$("#floor").text(res.floor);
						$("#canStay").text("预计"+formatDateTime(res.checkIn)+"可入住");
						$("#rent").text(rentTimeType[res.rentTimeType]+res.RentTime);
						$("#yajin").text(res.yj);
						$("#houseDesc").text(res.introduction);
						$("#green").text(res.green+"分");
						$("#leaseLength").text(res.leaseLength+"个月");
						$("#depositMethod").text(res.depositMethod);
						//交通
						var locationHtml = "";
						$("#locationUl").html("");
						locationHtml+="<li style='height: 30px;'>"+res.specialNote+"</li>";
						locationHtml+="<li style='height: 30px;'>公交车："+res.transport+"</li>";
						locationHtml+="<li style='height: 30px;'>地铁："+res.metro+"</li>";
						$("#locationUl").html(locationHtml);
						if(res.status=='2'){
							$("#yuyue").hide();
						}
					}
					//特征
					if(data.houseFlag!=null && data.houseFlag.length>0){
						var flagHtml = "";
						$("#flag").html("");
						$(data.houseFlag).each(function(i,n){
							flagHtml+="<span class='span_css'>"+n.flagName+"</span>&nbsp;&nbsp;";
						})
						$("#flag").html(flagHtml);
					}
					//小区
					if(data.community !=null ){
						$("#communityImg").html("<img src='"+data.c_img_list[0].img_url+"' style='margin-top: 0%;float: left;width: 25%;padding-top: 10px'/>");
						$("#communityName").text(data.community.community_name);
						$("#communityDesc").text(data.community.community_desc);
					}
					
					if(data.eset!=null){
						var html="";
						for(var i=0;i<data.eset.length;i++){
							html+="<li style=\"float: left; padding: 5px;min-width: 50px;line-height: 30px;border: 1px solid #9d9fe1;border-radius: 10px;margin-left: 5px;margin: 5px;\">"+data.eset[i].equipment_name;
							html+="</li>";
//							html+="<td>"+data.eset[i].equipment_name+"</td>";
//							html+="<td style='text-align:center'>"+data.eset[i].equipment_num+"件</td>";
//							html+="</tr>";
						}
						console.log(data);
						$("#shebei").html(html);
					}
					if(data.household != null){
						if(data.household.headImg != null){
							$("#headImg").html("<img src='"+data.household.headImg.split(",")[0]+"' style='margin-top: 0%;float: left;width: 25%;padding-left: 8px;padding-top: 10px'/>");	
						}
						
						$("#personalMsg").text(data.household.introduction);
						$("#houldName").text(data.household.houldName);
						$("#lianxi").attr("href","sms:"+data.household.phone);
					}
					if(data.houseCollect == true){
						$("#cang").parent().addClass("collect");
						$("#cang").attr("src","../images/collection1.png");
					}
				}else{
					$$.toast("查询详情出错，请联系管理员");
				}
			}
		});
	},
	getCookie : function (name) 
	{ 
	    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	 
	    if(arr=document.cookie.match(reg))
	 
	        return unescape(arr[2]); 
	    else 
	        return null; 
	} ,
	goback : function (){
		window.location.href="../jsp/lanjuZhengzu.html?grade="+grade;
	},
	toLink : function (txt,tagrt){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
				"phone" : HomeDetail.getCookie("phone")
			},
			success : function(data) {
				console.log(data);
				if(data.success){
					var url_="./" + txt;
					var arlArr=url_.split("?");
					if(arlArr.length>1){
						document.location.href = "./" + txt+"&userId="+data.user.userId+"&houseId="+houseId;
					}else{
						document.location.href = "./" + txt+"?userId="+data.user.userId+"&houseId="+houseId;
					}
					
				}else{
					 $$.alert(data.msg, function () {
				          window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
				        });
				}
			}
		});
		
	}
})
/**
 * 时间戳转yyyy-MM-dd
 * @param inputTime
 * @returns
 */
function formatDateTime(inputTime) {  
    var date = new Date(inputTime);
    var y = date.getFullYear();  
    var m = date.getMonth() + 1;  
    m = m < 10 ? ('0' + m) : m;  
    var d = date.getDate();  
    d = d < 10 ? ('0' + d) : d;  
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;  
    second = second < 10 ? ('0' + second) : second; 
    return y + '-' + m + '-' + d;  
   // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;  
};